package com.example.permission.controller;

import com.example.permission.annotation.ApiPermission;
import com.example.permission.entity.Menu;
import com.example.permission.enums.PermissionType;
import com.example.permission.service.UserPermissionService;
import com.example.permission.util.UserContext;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
public class MenuController {

    private final UserPermissionService userPermissionService;

    @ApiPermission(name = "获取当前用户的菜单", permissions = {PermissionType.READ})
    @GetMapping("/my")
    public List<Menu> getMyMenu() {
        Long uid = UserContext.get();
        return userPermissionService.getUserMenus(uid);
    }
}
